package org.frog.sgs.server;

import org.apache.mina.core.session.IoSession;
import org.frog.sgs.character.Character;
import org.frog.sgs.consts.Constants;
import org.frog.sgs.event.SgsEventCode;
import org.frog.sgs.io.SgsMsg;
import org.frog.sgs.server.game.ServerInstance;

/**
 * @author duanxiangqi
 * @date 2012-10-22
 */
public enum ServerMsgDispatcher {

	instance;

	public void dispatch(IoSession session, SgsMsg msg, ServerInstance instance) throws Exception {
		msg.readToBuffer();
		if (msg.getCode() != SgsEventCode.TOUCH_SERVER) {
			System.out.println("server receive:" + msg);
		}
		if (msg.getCode() < 1000) {

		} else {
			Character character = (Character) session.getAttribute(Constants.SESSION_KEY_CHARACTER);
			character.processMsg(msg);
		}
		msg.destory();
	}
}
